<?php
/**
 * Created by PhpStorm.
 * User: iceberg
 * Date: 2018-05-21
 * Time: 20:16
 */

namespace app\admin\validate;


use think\Validate;

class Admin extends Validate
{
    protected $rule = [
        'admin_name|用户名'        => 'require|unique:admin',
        'admin_role|用户角色'       => 'require|integer',
        'admin_password|用户密码'   => 'require',
        'repassword'              => 'require|confirm:admin_password',
        'yzm|验证码'               => 'require|captcha',
        '__token__'               => 'token',
    ];

    protected $message = [
        'tel.require'           => '电话号码必须',
        'tel.unique'            => '电话号码已经存在',
        'admin_role.require'    => '用户角色必须',
        'admin_role.integer'    => '用户角色必须为数字',
        'admin_password.require'=> '用户密码必须',
        'repassword.require'    => '确认密码必须',
        'repassword.confirm'    => '确认密码必须和密码一致',
        'yzm.require'           => '验证码必须',
        'yzm.captcha'           => '验证码错误',
        '__token__'             => '不能重复提交',
    ];

    protected $scene = [
        //'login' => ['admin_name', 'admin_password', 'yzm'],
        'add'   => ['tel', 'admin_password', 'admin_role', '__token__'],
        'edit'   => ['tel', 'admin_password', 'admin_role', '__token__'],
        'reg'   =>  ['tel', 'admin_password', 'admin_role', 'repassword', 'yzm'],
    ];

    // edit 验证场景定义
    public function sceneLogin()
    {
        return $this->only(['tel', 'admin_password', 'yzm'])
            ->remove('tel', 'unique');
    }

    // 没有验证码的login
    public function sceneLogin_no_yzm(){
        return $this->only(['tel', 'admin_password'])
            ->remove('tel', 'unique');
    }

}